﻿using Newtonsoft.Json;

namespace KwaiXiaoDian.Entity.Common
{
    /// <summary>
    /// ApiResult for Layui
    /// </summary>
    public class LayuiApiResult
    {
        /// <summary>
        /// 错误码，成功返回0
        /// </summary>
        public int Code { get; set; }

        /// <summary>
        /// 错误信息
        /// </summary>
        public string Msg { get; set; }

        /// <summary>
        /// 是否成功
        /// </summary>
        public bool IsSuccess
        {
            get
            {
                return Code == 0;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        public LayuiApiResult()
        {
            //ErrorCode = "A0001";
            //ErrorMessage = string.Empty;
            Code = 1001;
            Msg = "";
        }

        public LayuiApiResult(int code, string errorMessage)
        {
            //ErrorCode = errorCode;
            //ErrorMessage = errorMessage;
            Code = code;
            Msg = errorMessage;
        }
    }

    public class LayuiApiResult<T> : LayuiApiResult
    {
        [JsonProperty(Order = 99)]
        public T Data { get; set; }

        public LayuiApiResult() : base()
        { }

        public LayuiApiResult(int code, string errorMessage) : base(code, errorMessage)
        { }

        public LayuiApiResult(int code, string errorMessage, T data) : base(code, errorMessage)
        {
            Data = data;
        }
    }
}
